<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%@ include file="/WEB-INF/views/common.jsp"%>
<script type="text/javascript" src="../resource/layer/layer.js"></script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<script type="text/javascript">
	$(function(){
		var studentDatagrid = $('#studentDatagrid');
		var cmdObject = {
				searchAnswer : function() {
				if($("#keyValue").val() == '' || $("#keyValue").val() == null || $("#keyWord").val()=='') {
					return false;
				}
				if($("#keyWord").val() == 'studentNo') {
					$("#studentInfoNo").val($("#keyValue").val());
				}
				if($("#keyWord").val() == 'name') {
					$("#studentInfoName").val($("#keyValue").val());
				}
				$.ajax({
	                cache: false,
	                type: "POST",
	                url:"/answer/getStudentInfo",
	                data:$('#studentInfoForm').serialize(),
	                async: true,
	                success: function(data) {
	                    if(data.code == 1) {
	                    	$("#studentName").text(data.msg);
	                    	$("#studentThreeInfo").text(data.msg);
	                    	$("#studentScore").text(data.msg);
	                    } else {
	                    	$("#studentName").text(data.data.name);
	                    	$("#studentThreeInfo").text(data.data.threeInfo);
	                    	$("#studentScore").text(data.data.score);
	                    }
	                }
	            });
				studentDatagrid.datagrid('load',{
					"keyWord":$("select[name=keyWord]").val(),
					"keyValue":$("input[name=keyValue]").val()
				});
			}
		}
			$("a[data-cmd]").on('click', function() {
				var cmd = $(this).data("cmd");
				if (cmd && !$(this).hasClass('l-btn-disabled')) {
					cmdObject[cmd]();
				}
			});
	})
	function resultFormat(value, row, index) {
		if(value == null || value == '') {
			return '空';
		}
		if(row.type == 3) {
			if(value == 'A') {
				return '对';
			} else {
				return '错';
			}
		}
		return value;
	}
	function typeFormat(value, row, index) {
		if(value == 1) {
			return '单选';
		} else if(value == 2){
			return '多选';
		} else {
			return '判断';
		}
	}
	function choiceFormat(value, row, index) {
		if(row.type == 3) {
			return ""; 
		} else {
			var code = row.code;
			return '<input type="button"  style="cursor: pointer" value="查看选项" onclick="lookChoice('+code+')">';
		}
	}
	
	function lookChoice(code) {
		$.ajax({
			 cache: false,
             type: "GET",
             url:"/answer/lookChoice?questionId="+code,
             async: true,
             success: function(data) {
                 if(data.code == 0) {
                	 var str = '';
                	 var arr = data.data;
                	 for(var i in arr){  
                		 str = str + arr[i] + "<br/>"  
                		} 
                	 layer.alert(str,  {icon: 6});
                 } else {
                	 layer.alert("无数据");
                 }
             }
		});
	}
	
</script>
<body>
	<table id="studentDatagrid" class="easyui-datagrid"
		toolbar="#studentTooBar" url="/answer/list" pagination="true" fit="true"
		fitColumns="true" singleSelect="true" striped="true">
		<thead>
			<tr>
				<th field="code" align="center" width="40">错题编号</th>
				<th field="type" align="center" width="40" formatter="typeFormat">错题类型</th>
				<th field="intro" width="260">错题题干</th>
				<th field="other" align="center" formatter="choiceFormat">查看选项</th>
				<th field="resule" align="center" width="50" formatter="resultFormat">正确答案</th>
				<th field="errorResult" align="center" width="50" formatter="resultFormat">考生答案</th>
			</tr>
		</thead>
	</table>
	<div id="studentTooBar">
	<table>
		<tr>
			<form id="searchForm" method="post">
				<td>查询条件：</td>
				<td><select name="keyWord" style="width: 80px;height:25px;" id="keyWord">
						<option value="">--请选择--</option>
						<option value="studentNo">学号</option>
						<option value="name">姓名</option>
				</select>&nbsp;<input name="keyValue" style="width: 150px;height:20px;" id="keyValue"></td>
				<td><a id="search" href="javascript:void(0)"
					class="easyui-linkbutton" iconCls="icon-search" style="height:25px;width:60px;"
					data-cmd="searchAnswer">搜索 </a></td>
			</form>
		</tr>
		<font color="blue" style="font-size:13.5px;">（提示：若初考未过，展示初考错题；若补考也没过，则展示(初/补)两次考试的错题）</font>
		<form id="studentInfoForm">
			<input type="hidden" id="studentInfoNo" name="studentInfoNo">
			<input type="hidden" id="studentInfoName" name="studentInfoName">
			<tr>
				<td>考生姓名：</td>
				<td><span style="" id="studentName"></span></td>
			</tr>
			<tr>
				<td>学院专业：</td>
				<td><span style="" id="studentThreeInfo"></span></td>
			</tr>
			<tr>
				<td>考试分数：</td>
				<td><span style="color:red" id="studentScore"></span></td>
			</tr>
		</form>
	</table>
	</div>
</body>
</html>